package com.ruoyi.controller;

import java.lang.reflect.Array;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.ZhwyRentalcontract;
import com.ruoyi.service.IZhwyRentalcontractService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 租售合同Controller
 * 
 * @author ruoyi
 * @date 2024-05-07
 */
@RestController
@RequestMapping("/feeSettings/rentalcontract")
public class ZhwyRentalcontractController extends BaseController
{
    @Autowired
    private IZhwyRentalcontractService zhwyRentalcontractService;

    /**
     * 查询租售合同列表
     */
    @PreAuthorize("@ss.hasPermi('feeSettings:rentalcontract:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZhwyRentalcontract zhwyRentalcontract)
    {
        startPage();
        List<ZhwyRentalcontract> list = zhwyRentalcontractService.selectZhwyRentalcontractList(zhwyRentalcontract);
        return getDataTable(list);
    }

    /**
     * 导出租售合同列表
     */
    @PreAuthorize("@ss.hasPermi('feeSettings:rentalcontract:export')")
    @Log(title = "租售合同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZhwyRentalcontract zhwyRentalcontract)
    {
        List<ZhwyRentalcontract> list = zhwyRentalcontractService.selectZhwyRentalcontractList(zhwyRentalcontract);
        ExcelUtil<ZhwyRentalcontract> util = new ExcelUtil<ZhwyRentalcontract>(ZhwyRentalcontract.class);
        util.exportExcel(response, list, "租售合同数据");
    }
    /**
     * 获取租售合同详细信息
     */
    @PreAuthorize("@ss.hasPermi('feeSettings:rentalcontract:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zhwyRentalcontractService.selectZhwyRentalcontractById(id));
    }
    /**
     * 新增租售合同
     */
    @PreAuthorize("@ss.hasPermi('feeSettings:rentalcontract:add')")
    @Log(title = "租售合同", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZhwyRentalcontract zhwyRentalcontract)
    {
        System.out.println("============"+zhwyRentalcontract);
        return toAjax(zhwyRentalcontractService.insertZhwyRentalcontract(zhwyRentalcontract));
    }

    /**
     * 修改租售合同
     */
    @PreAuthorize("@ss.hasPermi('feeSettings:rentalcontract:edit')")
    @Log(title = "租售合同", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZhwyRentalcontract zhwyRentalcontract)
    {
        return toAjax(zhwyRentalcontractService.updateZhwyRentalcontract(zhwyRentalcontract));
    }

    /**
     * 删除租售合同
     */
    @PreAuthorize("@ss.hasPermi('feeSettings:rentalcontract:remove')")
    @Log(title = "租售合同", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zhwyRentalcontractService.deleteZhwyRentalcontractByIds(ids));
    }



    @Anonymous
    @GetMapping("/{did}/{bid}")
    public Map selectDBid(@PathVariable Long did,@PathVariable Long bid){
        Map map = zhwyRentalcontractService.select(did, bid);
        return map;
    }

    //    将合同状态修改为撤销状态
    @PutMapping("/{id}")
    public int updateState(@PathVariable Long id){
        return zhwyRentalcontractService.updateState(id);
    }


}
